package com.example.onlineeducation.data.json

import com.google.gson.annotations.SerializedName
import com.yc.jetpacklib.extension.ycIsNotEmpty
import com.yc.jetpacklib.extension.ycToNoEmpty
import java.math.BigDecimal


data class ExamResultDetailJson(
    @SerializedName("answerInfo") val answerInfo: List<AnswerInfo?>?,
    @SerializedName("isPass") val isPass: String?,//是否通过,0-未通过,1-已通过
    @SerializedName("isTrueNum") val isTrueNum: Int?,//答对数目
    @SerializedName("name") val examName: String?,//考试名称
) {
    fun getCorrectRate(): Float {
        return if (answerInfo.ycIsNotEmpty()) {
            (BigDecimal(isTrueNum.ycToNoEmpty(0)).divide(BigDecimal(answerInfo!!.size), 2, BigDecimal.ROUND_HALF_UP)).toFloat() * 100
        } else {
            0f
        }
    }

    data class AnswerInfo(
        @SerializedName("content") val content: String?,//题目内容
        @SerializedName("isRight") val isRight: String?,//该题是否答对   0-否,1-是
        @SerializedName("options") val options: List<Option?>?,//题目选项
        @SerializedName("personOptionIds") val userSelectOptionIds: List<String>?,//用户答题id
        @SerializedName("questionId") val questionId: String?,//题目id
        @SerializedName("type") val type: String?,//题目类型
    ) {

        data class Option(
            @SerializedName("content") val content: String?,//内容
            @SerializedName("id") val id: String?,//
            @SerializedName("isAnswer") val isAnswer: String?,//是否正确答案,  0-否,1-是
            @SerializedName("isDelete") val isDelete: String?,//是否删除: 0-否,1-是
            @SerializedName("mediaId") val materialId: String?,//素材文件id
            @SerializedName("questionId") val questionId: String//题目id
        )
    }


}


